package com.wangsd.web.face.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wangsd.web.face.entity.Advertisement;
import com.wangsd.web.face.entity.AdvertisementStoreRelation;
import com.wangsd.web.face.mapper.AdvertisementStoreRelationMapper;
import com.wangsd.web.face.service.AdvertisementStoreRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author generator
 * @since 2019-10-29
 */
@Service
public class AdvertisementStoreRelationServiceImpl extends ServiceImpl<AdvertisementStoreRelationMapper, AdvertisementStoreRelation> implements AdvertisementStoreRelationService {

    @Resource
    AdvertisementStoreRelationMapper advertisementStoreRelationMapper;

    @Override
    public List<Long> selectStoreIdsByAdvertisementId(Long advertisementId) {
        List<AdvertisementStoreRelation> relations = advertisementStoreRelationMapper.selectList(new QueryWrapper<AdvertisementStoreRelation>()
                .eq("advertisement_id", advertisementId));
        List<Long> collect = null;
        if (relations != null) {
            collect = relations.stream().map(AdvertisementStoreRelation::getStoreId).collect(Collectors.toList());
        }
        return collect;
    }

    @Override
    public List<Long> selectAdvertisementChoose(Long storeId) {
        List<AdvertisementStoreRelation> relations = advertisementStoreRelationMapper.selectList(new QueryWrapper<AdvertisementStoreRelation>()
                .eq("store_id", storeId));
        List<Long> collect = null;
        if (relations != null) {
            collect = relations.stream().map(AdvertisementStoreRelation::getAdvertisementId).collect(Collectors.toList());
        }
        return collect;
    }

    @Override
    public List<Advertisement> selectAdvertisementByStoreId(List<Long> storeId) {
        List<Advertisement> relations = advertisementStoreRelationMapper.selectAdvertisementByStoreId(storeId);
        return relations;
    }
}
